package com.jdjr.drools.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jdjr.drools.core.util.DroolsUtils;
import com.jdjr.drools.entity.Rules;
import com.jdjr.drools.entity.User;
import com.jdjr.drools.service.IRulesService;
import com.jdjr.drools.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Slf4j
public class UserController {

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IRulesService rulesService;

    @RequestMapping("/testDrools")
    @ResponseBody
    public Object testDrools() {
        List<User> users = iUserService.selectList(new EntityWrapper<User>(new User()));
        Rules rules = rulesService.selectOne(new EntityWrapper<>(new Rules().setPackageName("drools.example")));
        String installRule = DroolsUtils.installRule(rules);

        DroolsUtils.reload(installRule, users);

        return users;
    }

    @RequestMapping("/testQuery")
    @ResponseBody
    public Object testQuery(){
        List<User> users = iUserService.selectList(new EntityWrapper<User>(new User()));
        return null;

    }

}
